/*
Copyright (C) 2013 Matthew Netsch

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef PASSMODEL_H
#define PASSMODEL_H

#include "passman.h"
#include <QStandardItemModel>
#include <QString>

class PassModel : public QStandardItemModel, public PassMan::IDatabase::IObserver
{
    Q_OBJECT
public:
    explicit PassModel(PassMan::IDatabase *db, bool showPass, QObject *parent = 0);
    virtual ~PassModel();

    virtual void notify();

    PassMan::IDatabase* clone();
    bool isEqual(PassMan::IDatabase *db);

signals:
    void modelChanged();
    
public slots:
    void addPass(QString name, QString value);
    void deleteRow(int row);
    void changePass(int row, char *value);
    void updateModel(QStandardItem *item);
    void copyPass(int row);
    void setShowPass(bool show);

private:
    void initState();
    void enableUpdates();
    void disableUpdates();

    PassMan::IDatabase *db;
    bool refresh;
    bool showPass;

    QString passify(QString text);
};

#endif // PASSMODEL_H
